//
//  AppDelegate.m
//  小胖兔旅行指南
//
//  Created by 小胖兔 on 15/4/10.
//  Copyright (c) 2015年 小胖兔. All rights reserved.
//

#import "AppDelegate.h"
#import "MainViewController.h"
#import "SpecialViewController.h"
#import "ScenicViewController.h"
#import "MyViewController.h"

@interface AppDelegate ()

@end

@implementation AppDelegate

- (void)dealloc
{
    [_window release];
    
    [super dealloc];
}


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    [self.window setBackgroundColor:[UIColor whiteColor]];
    [self.window makeKeyAndVisible];
    [self.window release];
    // 首页
    MainViewController *main = [[MainViewController alloc] init];
    UINavigationController *navMain = [[UINavigationController alloc] initWithRootViewController:main];
    [main release];
    NSString *strMain = [[NSBundle mainBundle] pathForResource:@"main" ofType:@"png"];
    UIImage *imageMain = [UIImage imageWithContentsOfFile:strMain];
    UIImage *showMain = [imageMain imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    NSString *strMain1 = [[NSBundle mainBundle] pathForResource:@"main1" ofType:@"png"];
    UIImage *imageMain1 = [UIImage imageWithContentsOfFile:strMain1];
    UIImage *showMain1 = [imageMain1 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    main.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"首页" image:showMain selectedImage:showMain1];
    
    
    
    
    // 专题
    SpecialViewController *special = [[SpecialViewController alloc] init];
    UINavigationController *navSpecial = [[UINavigationController alloc] initWithRootViewController:special];
    [special release];
    NSString *strSpecial = [[NSBundle mainBundle] pathForResource:@"special" ofType:@"png"];
    UIImage *imageSpecial = [UIImage imageWithContentsOfFile:strSpecial];
    UIImage *showSpecial = [imageSpecial imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    NSString *strSpecial1 = [[NSBundle mainBundle] pathForResource:@"special1" ofType:@"png"];
    UIImage *imageSpecial1 = [UIImage imageWithContentsOfFile:strSpecial1];
    UIImage *showSpecial1 = [imageSpecial1 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    special.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"专题" image:showSpecial selectedImage:showSpecial1];
    
    
    
    // 景点
    ScenicViewController *scenic = [[ScenicViewController alloc] init];
    UINavigationController *navScenic = [[UINavigationController alloc] initWithRootViewController:scenic];
    [scenic release];
    NSString *strScenic = [[NSBundle mainBundle] pathForResource:@"scenic" ofType:@"png"];
    UIImage *imageScenic = [UIImage imageWithContentsOfFile:strScenic];
    UIImage *showScenic = [imageScenic imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    NSString *strScenic1 = [[NSBundle mainBundle] pathForResource:@"scenic1" ofType:@"png"];
    UIImage *imageScenic1 = [UIImage imageWithContentsOfFile:strScenic1];
    UIImage *showScenic1 = [imageScenic1 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    scenic.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"景点" image:showScenic selectedImage:showScenic1];

    // 首页
    MyViewController *my = [[MyViewController alloc] init];
    UINavigationController *navMy = [[UINavigationController alloc] initWithRootViewController:my];
    [my release];
    NSString *strMy = [[NSBundle mainBundle] pathForResource:@"my" ofType:@"png"];
    UIImage *imageMy = [UIImage imageWithContentsOfFile:strMy];
    UIImage *showMy = [imageMy imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    NSString *strMy1 = [[NSBundle mainBundle] pathForResource:@"my1" ofType:@"png"];
    UIImage *imageMy1 = [UIImage imageWithContentsOfFile:strMy1];
    UIImage *showMy1 = [imageMy1 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    my.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"我的" image:showMy selectedImage:showMy1];
    
    // 建立tabbar
    UITabBarController *tabBarController = [[UITabBarController alloc] init];
    tabBarController.viewControllers = [NSArray arrayWithObjects:navMain, navSpecial, navScenic, navMy, nil];
    [navMain release];
    [navSpecial release];
    [navScenic release];
    [navMy release];
    [tabBarController.tabBar setTranslucent:NO];
    [tabBarController.tabBar setAutoresizesSubviews:YES];
    [[UINavigationBar appearance] setTranslucent:NO];
    [[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:58.0 / 255.0 green:165.0 / 255.0 blue:222.0 / 255.0 alpha:1]];
    [[UINavigationBar appearance] setAutoresizesSubviews:YES];

    [self.window setRootViewController:tabBarController];
    [tabBarController release];

    
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
